package team.hyznrj.studentsys.configuration;

import javax.servlet.Filter;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import team.hyznrj.studentsys.StudentsysApplication;
import team.hyznrj.studentsys.filter.LoginFilter;

//@Configuration
public class FilterConfiguration extends SpringBootServletInitializer {
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(StudentsysApplication.class);
	}

	@Bean
	public FilterRegistrationBean contextFilterRegistrationBean() {
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		registrationBean.setFilter(loginFilter());
		registrationBean.addUrlPatterns("/");
		registrationBean.setName("requestFilter");
		registrationBean.setOrder(1);
		return registrationBean;
	}

	@Bean
	public Filter loginFilter() {
		return new LoginFilter();
	}
}
